package com.sfx.算法专题.双指针.n数之和;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-07-26
 * Time: 9:56
 */
public class Code_3_twoSum2 {

    static class Solution {
        public int[] twoSum(int[] nums, int target) {
            int l = 0;
            int r = nums.length - 1;
            int[] res = new int[2];
            while(l < r) {
                if(nums[l] + nums[r] > target) {
                    r--;
                }else if(nums[l] + nums[r] < target) {
                    l++;
                }else {
                    res[0] = l+1;
                    res[1] = r+1;
                    return res;
                }
            }
            return res;
        }
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {2,7,11,15};
        solution.twoSum(nums,9);
    }
}
